home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / newsgrp / group97a.txt / 000002_icon-group-sender _Fri Jan 3 09:21:34 1997.msg < prev    next >
Internet Message Format  |  2000-09-20  |  2KB

  1. Received: by cheltenham.cs.arizona.edu; Fri, 3 Jan 1997 17:23:19 MST
  2. Message-Id: <1.5.4.32.19970103152134.0071bfe4@post.its.mcw.edu>
  3. X-Sender: cdt@post.its.mcw.edu
  4. X-Mailer: Windows Eudora Light Version 1.5.4 (32)
  5. Mime-Version: 1.0
  6. Content-Type: text/plain; charset="us-ascii"
  7. Date: Fri, 03 Jan 1997 09:21:34 -0600
  8. To: icon-group@cs.arizona.edu
  9. From: Chris Tenaglia <cdt@post.its.mcw.edu>
  10. Subject: RE: Help for Icon Neophyte
  11. Errors-To: icon-group-errors@cs.arizona.edu
  12. Status: RO
  13. Content-Length: 1724
  14.  
  15. I think this does basically the same thing. It solves the
  16. case problem. map() coverts to lower case by default.
  17. Your code looked more like classical icon. Mine uses
  18. 3gl style. This looks more boring, but if I want to
  19. diddle the code, then I want the steps separated a little so
  20. more can be added later easier. Also think about
  21. your procedures. You can chunk things a dozen different
  22. ways. Some are far more maintainable. For example,
  23. my parse() procedure is general enough that I've re-used
  24. it in a 1000 other icon programs. I think each procedure
  25. should do one thing. If a procedure does several things
  26. it becomes less re-usable and more likely to have side
  27. effects if changed.
  28.  
  29. I've read both books. Dr. Corre's book is best read after
  30. The Icon Programming Language. Dr. Corre's book helped
  31. me understand string scanning. Until then I used string
  32. scanning, borrowed from other programs, but didn't know
  33. enough to write my own. I still don't get coexpressions
  34. and I've been programming icon since 1987.
  35.  
  36. procedure main()
  37.   count := table(0)
  38.   while line := map(read()) do
  39.     {
  40.     words := parse(line,' ,.;:!?')
  41.     every count[!words] +:= 1
  42.     }
  43.   result := sort(count)
  44.   every pair := !result do write(pair[1]," : ",pair[2])
  45.   end
  46.  
  47.  
  48. #
  49. # parse a string into a list with respect to a delimiter
  50. #
  51. procedure parse(line,delims)
  52.   static chars
  53.   chars  := &cset -- delims
  54.   tokens := []
  55.   line ? while tab(upto(chars)) do put(tokens,tab(many(chars)))
  56.   return tokens
  57.   end
  58.  
  59. Chris Tenaglia (system manager)         |       cdt@post.its.mcw.edu
  60. Medical College of Wisconsin            |
  61. 8701 W. Watertown Plank Rd.             |      Ce que vous voyez est
  62. Milwaukee, WI 53226 (414)456-8765       |      Ce que vous obtenez !
  63.  
  64.